from django.db import models


# Create your models here.
class Student(models.Model):
    SEX_CHOICES = (
        (0, '女'),
        (1, '男')
    )
    name = models.CharField(max_length=30, verbose_name='姓名')  # verbose_name是姓名备注，如果没有写备注，显示的就是name
    age = models.IntegerField(verbose_name='年龄', null=True, blank=True)  # null当前数据可以为空，blank前端数据可以不传递
    sex = models.IntegerField(verbose_name='性别', null=True, blank=True, choices=SEX_CHOICES)  # choices下拉框
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='更改时间')
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除')  # 数据暂存，不会轻易删除

    # 一对多关系ForeignKey  备注名字verbose_name
    classes = models.ForeignKey('Classes', on_delete=models.CASCADE, verbose_name='班级')

    # 逻辑删除
    def delete(self, using=None, keep_parents=False):
        self.is_delete = True
        self.save()


# 班级的模型类
class Classes(models.Model):
    name = models.CharField(max_length=30, verbose_name='班级名')
    slogan = models.TextField(null=True,blank=True, verbose_name='口号')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='更改时间')
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除')  # 数据暂存，不会轻易删除

# 逻辑删除
    def delete(self, using=None, keep_parents=False):
        self.is_delete = True
        self.save()

    def __str__(self):
        return self.name